<?php
/**
 * Created by PhpStorm.
 * User: 87393
 * Date: 2019-03-27
 * Time: 11:44
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IRole;
use App\Http\Repositories\Services\ISystem;
use App\Http\Requests\Admin\SystemInputDTO;
use App\Util\LayUiVo;
use App\Util\ResultsVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class SystemController extends Controller
{

    protected $systemService;
    protected $roleService;

    public function __construct(ISystem $systemService,IRole $roleService)
    {
        $this->systemService = $systemService;
        $this->roleService = $roleService;
    }

    public function page(Request $request) {
        $search = [];
        $page = $request->get('page', 1);
        $size = $request->get('size', 10);
        $data = $this->systemService->lists($search, $page, $size);
        return response()->json(new LayUiVo(['data'=>$data],[],['password','salt']));
    }

    public function store(SystemInputDTO $inputDTO) {
        $this->systemService->store($inputDTO);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function update(SystemInputDTO $inputDTO, $id) {
        $this->systemService->update($inputDTO, $id);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function show($id) {
        $data = $this->systemService->byId($id);
        return response()->json(new ResultsVo(['data'=>$data->toArray()],[],['password','updated_at','salt']));
    }

    public function state($id, $state) {
        $this->systemService->state($id, $state);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')],[],[]));
    }

}